#include <iostream>
#include <sys/ipc.h>
#include <sys/shm.h>
using namespace std;
// const char* path = "/usr/IPC";
int main()
{
	key_t key;
	int shmId;
	int i = 0;
	
	// key = ftok(path, 1);//生成键值
	// if(key == -1)
	// {
	// 	cout << "ftok failed" << endl;
	// }
	
	shmId = shmget(key, 0, 0);
	cout << "shmId=" << shmId << endl;
	if(shmId == -1)
	{
		cout << "shmget failed" << endl;
	}
	
	int* shmaddr = (int*)shmat(shmId, NULL, 0); //获取共享内存地址
	
	for(i = 0; i < 5;i++)
	{
	//从共享内存读取数据
		cout << *shmaddr << endl;
		shmaddr++;
	}
	cout << "read end" << endl;	
}
